// 该文件专门用于创建整个应用的路由器
import VueRouter from 'vue-router'
//引入组件
import Login from '../views/Login'
import Violation from '../views/Violation'
import { CheckLogin } from '@/utils/login'
import Null from '../views/Null'
const routes = [
	{
		path: '/login',
		name: 'login',
		component: Login
	},
	{
		path: '/',
		name: 'home',
		component: () => import('@/views/Home'),
		// component:Index,
		redirect:'/department',
		children: [
			// {
			// 	path: '/welcome',
			// 	component: Violation,
			// 	meta: {
			// 		title: '主页',
			// 		icon: 'el-icon-s-home',
			// 	},
			// },
			{
				path: '/system',
				meta: {
					title: '系统管理',
					icon: 'el-icon-setting'
				},
				// redirect:'/department',
				component: Null,
				children: [
					{
						path: '/department',
						name: 'department',
						component: () => import('@/views/department/DepartmentList'),
						meta: {
							title: '部门管理',
							icon: 'el-icon-office-building'
						}
					},
					{
						path: '/role',
						name: 'role',
						component: () => import('@/views/role/Role'),
						meta: {
							title: '职位管理',
							icon: 'el-icon-suitcase-1'
						}
					},
					{
						path: '/adminuser/list',
						name: 'adminuser',
						component: () => import('@/views/adminuser/AdminUser'),
						meta: {
							title: '教职工管理',
							icon: 'el-icon-s-custom'
						},
						redirect: '/adminuser/list',
						children: [
							{
								path: '/adminuser/list',
								name: 'adminuser-list',
								component: () => import('@/views/adminuser/AdminUserList'),
								meta: {
									title: '教职工列表',
									icon: ''
								}
							},
							{
								path: '/adminuser/add',
								component: () => import('@/views/adminuser/AdminUserForm'),
								meta: {
									title: '添加教职工',
									icon: ''
								}
							},
						]
					},
				]
			},
			{
				path: '/colleges',
				meta: {
					title: '学院管理（教务）',
					icon: 'el-icon-user'
				},
				// redirect:'/department',
				component: Null,
				children:[
					{
						path: '/teaching',
						name: 'teaching',
						component: () => import('@/views/teaching/TeachingCycle'),
						meta: {
							title: '教学周期',
							icon: 'el-icon-date'
						}
					},
					// Attendance
					{
						path: '/attendance',
						name: 'attendance',
						component: () => import('@/views/teaching/Attendance'),
						meta: {
							title: '出勤率汇总',
							icon: 'el-icon-date'
						}
					},
					{
						path: '/class_hour',
						name: 'class_hour',
						component: () => import('@/views/teaching/ClassHour'),
						meta: {
							title: '讲师课时',
							icon: 'el-icon-date'
						}
					},
					{
						path: '/Coursetable',
						name: 'Coursetable',
						component: () => import('@/views/teaching/Coursetable'),
						meta: {
							title: '教务排课表',
							icon: 'el-icon-date'
						}
					},
					{
						path: '/class',
						name: 'class',
						component: () => import('@/views/school/Class'),
						meta: {
							title: '班级管理',
							icon: 'el-icon-s-management'
						}
					},
					{
						path: '/students',
						name: 'students',
						component: () => import('@/views/school/Students'),
						meta: {
							title: '学生管理',
							icon: 'el-icon-user-solid'
						}
					},
					{
						path: '/roll_sheet',
						name: 'roll_sheet',
						component: () => import('@/views/teaching/RollSheet'),
						meta: {
							title: '点名表',
							icon: 'el-icon-user-solid'
						}
					},
					
				]
			},
			{
				path: '/college',
				meta: {
					title: '学院管理（学院）',
					icon: 'el-icon-star-off'
				},
				// redirect:'/department',
				component: Null,
				children:[
					{
						path: '/CollegeCoursetable',
						name: 'CollegeCoursetable',
						component: () => import('@/views/school/CollegeCoursetable'),
						meta: {
							title: '学院排课表',
							icon: 'el-icon-s-flag'
						}
					},
					{
						path: '/college_stage',
						name: 'college_stage',
						component: () => import('@/views/school/CollegeStage'),
						meta: {
							title: '课程阶段',
							icon: 'el-icon-s-flag'
						}
					},
					{
						path: '/curriculum',
						name: 'curriculum',
						component: () => import('@/views/school/Curriculum'),
						meta: {
							title: '课程体系',
							icon: 'el-icon-s-flag'
						}
					},
					{
						path: '/adjust-course',
						name: 'adjust-course',
						component: () => import('@/views/teaching/AdjustCourse'),
						meta: {
							title: '点名/调课/代课',
							icon: 'el-icon-s-flag'
						}
					},
					{
						path: '/roll-call/:id',
						name: 'roll-call',
						component: () => import('@/views/teaching/RollCall'),
						props: true,
						meta: {
							title: '点名',
							icon: 'el-icon-thumb',
							is_show: false
						}
					},
					{
						path: '/roll-sheet_call/:id',
						name: 'roll-sheet_call',
						component: () => import('@/views/teaching/RollSheetCall'),
						props: true,
						meta: {
							title: '点名',
							icon: 'el-icon-thumb',
							is_show: false
						}
					},
					{
						path: '/adjust-classtime',
						name: 'adjust-classtime',
						component: () => import('@/views/teaching/AdjustClassTimeList'),
						meta: {
							title: '调课记录',
							icon: 'el-icon-guide'
						}
					},
					{
						path: '/RiseEndClass',
						name: 'RiseEndClass',
						component: () => import('@/views/school/RiseEndClass'),
						meta: {
							title: '学生升末班',
							icon: 'el-icon-s-flag'
						}
					},
				]
			},
		]
	}
]


//创建并暴露一个路由器
const router = new VueRouter({
	routes
})



//全局前置路由守卫————初始化的时候被调用、每次路由切换之前被调用
router.beforeEach((to, from, next) => {
	if (to.name != 'login') { //判断是否需要鉴权
		if (CheckLogin()) {
			next()
		} else {
			router.replace({ name: 'login' })
		}
	} else {
		next()
	}
})

//全局后置路由守卫————初始化的时候被调用、每次路由切换之后被调用
router.afterEach((to, from) => {
	window.localStorage.setItem('path', to.path)
	document.title = to.meta.title || '振涛教育教学管理平台'
})

export default router
